<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<%@include file="../../public/commonJs.jsp" %>
<%@include file="../../public/commonCss.jsp" %>
<div style="background-color: #fff" ms-controller="main">
    <div class="layui-form">
        <input type="hidden" name="roleType" value="${roleType}"></input>
        <div style="width:100%;height:100%;background-color: #fff;">
            <!-- content -->
            <div style="overflow:auto;">
                <div class="layui-form-item" style="margin-top:50px;width:500px">
                    <label class="layui-form-label" style="font-size:16px;width:100px;">所拥有菜单：</label>
                    <div class="layui-input-block" style="margin-left:130px;">
                        <c:forEach items="${menus}" var="menu">
                            <input type="checkbox" name="roleMenus[${menu.id}]" title="${menu.name}"
                                   value="${menu.name}"
                                   <c:if test="${menu.isCheck=='true'}">checked</c:if> >
                        </c:forEach>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top:50px">
                    <div class="layui-input-block" style="margin-left:130px;">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary" onclick="closeLayer()">取消</button>
                    </div>
                </div>
            </div>
            <!-- content -->
        </div>
    </div>
</div>
<script type="text/javascript">
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var form = layui.form();
    form.on('submit(formDemo)', function (data) {
        console.log(data.field);
        //这里执行ajax提交
        $.ajax({
            type: 'post',
            url: '${ctx}/roleMenuController/saveRoleMenu.action',
            data: data.field,
            dataType: "json",
            timeout: 10000,
            beforeSend: function () {
                parent.layer.msg('正在保存数据...', {
                    icon: 16,
                    shade: 0.01
                });
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg('保存成功', {icon: 1});
                } else {
                    parent.layer.msg('保存失败，请重试', {icon: 2});
                }
            }
        });
        return false;
    });
    form.render();
    //关闭对话框
    function closeLayer() {
        parent.setIframeSrc("");
    }
</script>